	function compareDate(dateStr1, dateStr2, dateFormat, formatChar) {
		// sample : compareDate('02/13/2007', '02/15/2007', 'MM/dd/yyyy', '/');
		// sample : compareDate('15/01/07', '30/12/06'); use default format
		// return:
		// 1 big
		// 0 equal
		// -1 small
		// 2 dateStr1 is empty
		// 3 dateStr2 is empty
		// 4 invalid dateFormat
		// 5 invalid dateStr1 format
		// 6 invalid dateStr2 format
		if(isEmpty(dateFormat)){dateFormat = "MM/dd/yy";}
		if(isEmpty(formatChar)){formatChar = "/";}
		var monthStr1 = "";
		var dayStr1 = "";
		var yearStr1 = "";
		var monthStr2 = "";
		var dayStr2 = "";
		var yearStr2 = "";
		var month1 = "";
		var day1 = "";
		var year1 = "";
		var month2 = "";
		var day2 = "";
		var year2 = "";
		if(isEmpty(dateStr1)){return 2;} 
		if(isEmpty(dateStr2)){return 3;} 
		var dateFormatArray = dateFormat.split(formatChar);
		if(dateFormatArray.length!=3){return 4;}
		var dateArray1 =dateStr1.split(formatChar);
		if(dateArray1.length!=3){return 5;}
		var dateArray2 =dateStr2.split(formatChar);
		if(dateArray2.length!=3){return 6;}
		for(var i=0; i<3; i++){
			if((dateFormatArray[i]=="d") || (dateFormatArray[i]=="dd")){
				dayStr1 = dateArray1[i];
				if(!isInt(dayStr1)){return 5;}
				day1 = parseInt(dayStr1,10);
				dayStr2 = dateArray2[i];
				if(!isInt(dayStr2)){return 6;}
				day2 = parseInt(dayStr2,10);
			}else if((dateFormatArray[i]=="M") || (dateFormatArray[i]=="MM")){
				monthStr1 = dateArray1[i];
				if(!isInt(monthStr1)){return 5;}
				month1 = parseInt(monthStr1,10);
				monthStr2 = dateArray2[i];
				if(!isInt(monthStr2)){return 6;}
				month2 = parseInt(monthStr2,10);
			}else if((dateFormatArray[i]=="yy") || (dateFormatArray[i]=="yyyy")){
				yearStr1 = dateArray1[i];
				if(!isInt(yearStr1)){return 5;}
				year1 = parseInt(yearStr1,10);
				year1 = (year1<50)?(year1+2000):year1;
				yearStr2 = dateArray2[i];
				if(!isInt(yearStr2)){return 6;}
				year2 = parseInt(yearStr2,10);
				year2 = (year2<50)?(year2+2000):year2;
			}else{
				return 4;
			}
		}
		var dateObj1 = Date.parse(month1+"/"+day1+"/"+year1);
		var dateObj2 = Date.parse(month2+"/"+day2+"/"+year2);
		if(dateObj1 > dateObj2) {
			return 1;
		}else if(dateObj1 == dateObj2){
			return 0;
		}else{
			return -1;
		}
	}
	
	function isDate(dateStr, dateFormat, formatChar){
		if(isEmpty(dateFormat)){dateFormat = "dd/MM/yy";} // default dateFormat
		if(isEmpty(formatChar)){formatChar = "/";} // default fromatChar
		var dateFormatArray = dateFormat.split(formatChar);
		if(dateFormatArray.length!=3){return false;}
		if(isEmpty(dateStr)){return false;} 
		var dateArray =dateStr.split(formatChar);
		if(dateArray.length!=3){return false;}
		var monthStr = "";
		var month;
		var dayStr = "";
		var day;
		var yearStr = "";
		var year;
		for(var i=0; i<3; i++){
			if((dateFormatArray[i]=="d") || (dateFormatArray[i]=="dd")){
				dayStr = dateArray[i];
				if(!isInt(dayStr)){return false;}
				day = parseInt(dayStr,10);
				// if(day<1 && day>31){return false;}
			}else if((dateFormatArray[i]=="M") || (dateFormatArray[i]=="MM")){
				monthStr = dateArray[i];
				if(!isInt(monthStr)){return false;}
				month = parseInt(dayStr,10);
				// if(month<1 && month>12){return false;}
			}else if((dateFormatArray[i]=="yy") || (dateFormatArray[i]=="yyyy")){
				yearStr = dateArray[i];
				if(!isInt(yearStr)){return false;}
				year = parseInt(dayStr,10);
			}else{
				return false;
			}
		}
		return true;
	}
	
	function isEmpty (str){
	 return ((str == null) || (trim(str).length == 0));
	}

	function trim(stringToTrim){	
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	
	function ltrim(stringToTrim){	
		return stringToTrim.replace(/^\s+/,"");
	}
	
	function rtrim(stringToTrim){	
		return stringToTrim.replace(/\s+$/,"");
	}	
	
	function isInt(str){
		if(isEmpty(str)) return false; 
		var strP = /^-?[0-9]\d*$/ ; 
		if(!strP.test(str)) return false; 
		return true;
	}

	function dateToString(dateIn, dateFormat, formatChar){
		if(isEmpty(dateFormat)){dateFormat = "dd/MM/yy";} // default dateFormat
		if(isEmpty(formatChar)){formatChar = "/";} // default fromatChar
	    var year = dateIn.getYear();
	    var month = dateIn.getMonth()+1;
 	   	var day = dateIn.getDate();
  		var dateOut = dateFormat;
			dateOut = dateOut.replace("dd", ((day<10)?('0'+day):day));
			dateOut = dateOut.replace("d", day);
			dateOut = dateOut.replace("MM", ((month<10)?('0'+month):month));
			dateOut = dateOut.replace("M", month);
			dateOut = dateOut.replace("yyyy", year);
			dateOut = dateOut.replace("yy",(((year%100)<10)?('0'+(year%100)):(year%100)));
	    return dateOut;
	}

function setOtherHiddenFields(event, val) {
}

function doSubmit(pageEvent) {
    doSubmitWithDisabledButtons(pageEvent, null);
}

function doSubmit(pageEvent, val) {
    doSubmitWithDisabledButtons(pageEvent, val);
}

function alertSaveMsg() {
  return true;
}
 
function alertDeleteMsg() {
  return true;
}

function disableButtonWhenSubmit(event) {
  if((event != null) 
		&& ( (event.substring(0, 6) == "export") || (event.substring(0, 5) == "print") || (event.substring(0, 8) == "download") )) {
		return false;
	} else {
		return true;
	}
}

function doSubmitWithDisabledButtons(event, val) {
	var form = document.forms[0];
	var disabledButtons = disableButtonWhenSubmit(event);

	setOtherHiddenFields(event, val);

	if(event == "confirmAdd"){
		if(!confirmConfirmAdd("")){
			return false;	
		}
	}

	if (event == "exit" ) {
	  if (alertSaveMsg()) {
		  if (!confirmExit("")) {
			  return false;
		  }
		}
	}

	if(event == "delete"){
	  if (alertDeleteMsg()) {
		  if (!confirmDelete("")){
			  return false;
		  }
		}
	}

	if(disabledButtons){
		var sItems = document.getElementsByTagName('input');

		for (i=0; i< sItems.length; i++) {
			if (sItems[i].type == 'button') {
				sItems[i].disabled = true;
			}
		}
	}

	document.forms[0].pageEvent.value = event;
	if (val != null) {
		document.forms[0].pageEventSrc.value = val;
	}
	doRemoveCommas();
	document.forms[0].submit();
}

function MM_reloadPage(init) {	//reloads the window if Nav4 resized
	if (init==true) with (navigator) {
		if ((appName=='Netscape')&&(parseInt(appVersion)==4)) {
			document.MM_pgW=innerWidth;
			document.MM_pgH=innerHeight;
			onresize=MM_reloadPage; 
		}
	}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
		location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
	var p,i,x;	
	if(!d) 
		d=document; 

	if(p=n.indexOf('?')>0 && parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}

	if(!(x=d[n])&&d.all) 
		x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];
	
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) 
		x=d.getElementById(n); 
	return x;
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj, args= MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) 
		if ((obj=MM_findObj(args[i]))!=null) { 
			v = args[i+2];
			if (obj.style) { 
				obj=obj.style; 
				v=(v=='show')?'visible':(v='hide')?'hidden':v; 
			}
			obj.visibility=v; 
		}
}

function MM_goToURL() { //v3.0
	var i, args=MM_goToURL.arguments; 
	document.MM_returnValue = false;
	for (i=0; i<(args.length-1); i+=2) 
		eval(args[i]+".location='"+args[i+1]+"'");
}

function showMenu(mno) {
	var eMenu = document.getElementById('Layer'+mno);
	eMenu.style.visibility = 'visible';
	var sItems = document.getElementsByTagName('SELECT');
	for (i=0; i<sItems.length; i++) {
		if (isOverLap(sItems[i],eMenu))
			sItems[i].style.visibility = 'hidden';
	}
}

function hideMenu(mno) {
	var eMenu = document.getElementById('Layer'+mno);
	eMenu.style.visibility = 'hidden';
	var sItems = document.getElementsByTagName('SELECT');
	for (i=0; i<sItems.length; i++) {
		if (sItems[i].style.visibility == 'hidden')
			sItems[i].style.visibility = 'visible';
	}
}

function isOverLap(ele,sMenu) {
	var left = 0;
	var top = 0;
	var width = ele.offsetWidth;
	var height = ele.offsetHeight;
	while (ele) {
		left += ele.offsetLeft;
		top += ele.offsetTop;
		ele = ele.offsetParent;
	}
	sLeft = sMenu.offsetParent.offsetLeft+sMenu.offsetLeft;
	sRight = sLeft + sMenu.offsetWidth;
	sTop = sMenu.offsetParent.offsetTop+sMenu.offsetTop;
	sBottom = sTop + sMenu.offsetHeight;
	return ((left < sRight) && (left + width > sLeft) && (top < sBottom) && (top + height > sTop));
}

function popup_msg() {
	var answer = window.confirm('Caller from : 50'+'\n'+'Ready to answer?');
	if(answer){this.location.href='custprofileselect_1.htm'};
}

function doProtect(val) {
	var sItems = document.getElementsByTagName('input');
	for (i=0; i < sItems.length; i++) {
		if(sItems[i].type == 'text'){
			sItems[i].readOnly= true;
		} else if(sItems[i].type == 'button'){
			sItems[i].style.visibility = "hidden";
		} else if(sItems[i].type == 'reset'){
			sItems[i].style.visibility = "hidden";
		} else if(sItems[i].type == 'submit'){
			sItems[i].style.visibility = "hidden";
		} else if (sItems[i].type == 'checkbox'){
			sItems[i].disabled = true;
		} else if (sItems[i].type == 'radio'){
			sItems[i].disabled = true;
		} else if (sItems[i].type == 'image'){
			sItems[i].disabled = true;
		}
	}
	sItems = document.getElementsByTagName('textarea');
	for (i=0; i < sItems.length; i++) {
		sItems[i].readOnly = true;
		//sItems[i].style.color = "#808080";
	}
	sItems = document.getElementsByTagName('select');
	for (i=0; i < sItems.length; i++) {
		sItems[i].disabled = true;
	}
}

function undoProtect(val) {
	var sItems = document.getElementsByTagName('input');
	for (i=0; i < sItems.length; i++) {
		if(sItems[i].type == 'text'){
			sItems[i].readOnly= false;
		} else if(sItems[i].type == 'button'){
			sItems[i].style.visibility = "visible";
		} else if(sItems[i].type == 'reset'){
			sItems[i].style.visibility = "visible";
		} else if(sItems[i].type == 'submit'){
			sItems[i].style.visibility = "visible";
		} else if (sItems[i].type == 'checkbox'){
			sItems[i].disabled = false;
		} else if (sItems[i].type == 'radio'){
			sItems[i].disabled = false;
		} else if (sItems[i].type == 'image'){
			sItems[i].disabled = false;
		}
	}
	sItems = document.getElementsByTagName('textarea');
	for (i=0; i < sItems.length; i++) {
		sItems[i].readOnly = false;
	}
	sItems = document.getElementsByTagName('select');
	for (i=0; i < sItems.length; i++) {
		sItems[i].disabled = false;
	}
}

function getCookie(nameOfCookie) {

	// First we check to see if there is a cookie stored.
	// Otherwise the length of document.cookie would be zero.

	if (document.cookie.length > 0) {

		// Second we check to see if the cookie's name is stored in the
		// 'document.cookie' object for the page.

		// Since more than one cookie can be set on a
		// single page it is possible that our cookie
		// is not present, even though the 'document.cookie' object
		// is not just an empty text.
		// If our cookie name is not present the value -1 is stored
		// in the variable called 'begin'.

		begin = document.cookie.indexOf(nameOfCookie+'=');
		if (begin != -1)  { // Note: != means 'is not equal to'
			// Our cookie was set.
			// The value stored in the cookie is returned from the function.

			begin += nameOfCookie.length+1;
			end = document.cookie.indexOf(';', begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;

	// Our cookie was not set.
	// The value 'null' is returned from the function.
}

function setCookie(nameOfCookie, value, expiredays) {

	// Three variables are used to set the new cookie.
	// The name of the cookie, the value to be stored,
	// and finally the number of days until the cookie expires.
	// The first lines in the function convert
	// the number of days to a valid date.

	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

	// The next line stores the cookie, simply by assigning
	// the values to the 'document.cookie' object.
	// Note the date is converted to Greenwich Mean time using
	// the 'toGMTstring()' function.

	document.cookie = nameOfCookie + '=' + escape(value) +
		((expiredays == null) ? '' : '; expires=' + ExpireDate.toGMTString());
}

function delCookie (nameOfCookie) {

	// The function simply checks to see if the cookie is set.
	// If so, the expiration date is set to Jan. 1st 1970.

	if (getCookie(nameOfCookie)) {
		document.cookie = nameOfCookie + '=; expires=Thu, 01-Jan-70 00:00:01 GMT';
	}
}

function goReportMain(){
	window.location.href = "reportmain.jsp";
}

function goMasterListMain(){
	window.location.href = "masterList.jsp";
}

function goEnquiryMain(){
	window.location.href = "enquiryList.jsp";
}

function doTwoRadioWithValue(cbName,idx,val1,val2) {
	firstVal = val1;
	secondVal = val2;
	doTwoRadio(cbName,idx);
	firstVal = '0';
	secondVal = '1';
}
function doTwoRadio(cbName,idx) {
	var aInput = document.getElementsByName(cbName);
	if (aInput.length) {
		selectedObj = aInput[idx];
		if (aInput.length == 1)
			selectedObj = aInput[0];
	} else {
		selectedObj = aInput;
	}
	if (selectedObj.value != null && selectedObj.value == firstVal)
		selectedObj.value = firstVal;
	else
		selectedObj.value = secondVal;
}

// autofill parameters
var autofill_prefix = "srch";
var autofill_suffix_fr = "Fr";
var autofill_suffix_to = "To";

function autofill_init(prefix, suffix_fr, suffix_to) {
	var elms = document.getElementsByTagName("input");
	
	if (typeof(prefix) != 'undefined' && prefix != '')
		autofill_prefix = prefix;
	
	if (typeof(suffix_fr) != 'undefined' && suffix_fr != '')
		autofill_suffix_fr = suffix_fr;
		
	if (typeof(suffix_to) != 'undefined' && suffix_to != '')
		autofill_suffix_to = suffix_to;
	
	for (var i = 0; i < elms.length; i++) {
		var e = elms[i];

		if (e.getAttribute('autofill')) {
			if (e.getAttribute('autofill').toLowerCase() == 'true')
				e.onblur = autofill;
			continue;
		}
			
		if (e.type == 'text' && e.name.substr(0, autofill_prefix.length) == autofill_prefix && e.name.substr(e.name.length - autofill_suffix_fr.length, autofill_suffix_fr.length) == autofill_suffix_fr)
			e.onblur = autofill;
	}
}

function findIndex(src) {
	var elms = document.getElementsByName(src.name);

	for (var i = 0; i < elms.length; i++) {
		if (elms[i] == src)
			return i;
	}
	
	return -1;
}

function autofill() {
	doAutofill(this);
}

function doAutofill(e) {
	var name = e.name;
	var idx = findIndex(e);
	var ts = document.getElementsByName(e.name.substr(0, e.name.length - autofill_suffix_fr.length) + autofill_suffix_to);
	
	if (idx == -1 || e.value == '')
		return;
	
	if (e.name.substr(0, autofill_prefix.length) == autofill_prefix && ts.length > 0) {
		var to = ts[idx];			
		
		if (to.value != '')
			return;
					
		to.value = to.value.length == 0 ? e.value : to.value;
		var tr = to.createTextRange();
		tr.select();
	}
}

function doTickWithValue(cbName,idx,val1,val2) {
	tickVal = val1;
	untickVal = val2;
	doTick(cbName,idx);
	tickVal = '0';
	untickVal = '1';
}

function doTick(cbName,idx) {
	var aInput = document.getElementsByName(cbName);
	if (aInput.length) {
		selectedObj = aInput[idx];
		if (aInput.length == 1)
			selectedObj = aInput[0];
	} else {
		selectedObj = aInput;
	}
	if (selectedObj.value != null && selectedObj.value == tickVal)
		selectedObj.value = untickVal;
	else
		selectedObj.value = tickVal;
}


function doViewRemark(name, idx, title1, value1, title2, value2, remarkTitle){
	var form = document.forms[0];
	var val="";
	var queryStr = "";
	var doc;
	//var stylePath = "<%=request.getContextPath()%>";

	if(form.elements[name]){
		if(form.elements[name].length){
			val = form.elements[name][idx].value;
		} else {
			val = form.elements[name].value;
		}
	}

	if(remarkWin && remarkWin.open && !remarkWin.closed){
		remarkWin.close();
	}

	remarkWin = window.open('remarkView.do','remarkWin','width=750,height=550,resizable=yes,menubar=no,scrollbars=yes,status=no');
	if(remarkWin && remarkWin.open && !remarkWin.closed){
		remarkWin.moveTo(0, 0);

		var content = "";
		content += "<head>" + "\n";
		content += "<title>View Remark</title>" + "\n";
		content += "<link rel=\"stylesheet\" href=\""+stylePath+"/css/style.css\" type=\"text/css\">" + "\n";
		content += "<script language=\"javascript\">" + "\n";
		content += "<!--" + "\n";
		content += "function doLoad() {" + "\n";
		content += "	window.resizeTo(750, 550);" + "\n";
		content += "	window.moveTo(0, 0);" + "\n";
		content += "}" + "\n";
		content += "-->" + "\n";
		content += "</script>" + "\n";
		content += "</head>" + "\n";
		content += "<body onLoad=\"javascript:doLoad();\" bgcolor=\"#ffffff\">" + "\n";
		content += "<table class=\"table_header\">" + "\n";
		if(!(title1 == null || title1 == "")){
			content += "	<tr valign=\"top\">" + "\n";
			content += "<td class=\"col_label\">"+title1+"</td>" + "\n";
			content += "<td class=\"col_value\">"+value1+"</td>" + "\n";
			content += "	</tr>" + "\n";
		}
		if(!(title2 == null || title2 == "")){
			content += "	<tr valign=\"top\">" + "\n";
			content += "<td class=\"col_label\">"+title2+"</td>" + "\n";
			content += "<td class=\"col_value\">"+value2+"</td>" + "\n";
			content += "	</tr>" + "\n";
		}
		content += "<tr valign=\"top\">" + "\n";
		content += "	<td class=\"col_label\"></td>" + "\n";
		content += "	<td class=\"col_value\">" + "\n";
		content += "	<input name=\"btn_close\" type=\"button\" value=\"close\" onClick=\"javascript:window.close();\" class=\"button1\">" + "\n";
		content += "	</td>" + "\n";
		content += "</tr>" + "\n";
		content += "<tr valign=\"top\">" + "\n";
		content += "	 <td class=\"col_label\">" + "\n";
		content += remarkTitle;
		content += "	 </td>" + "\n";
		content += "	 <td class=\"col_value\">" + "\n";
		content += "<textarea rows=\"25\" cols=\"75\" class=\"textarea1\" readonly>"+val+"</textarea>" + "\n";
		content += "	 </td>" + "\n";
		content += "</tr>" + "\n";
		content += "</table>" + "\n";
		content += "</body>" + "\n";

		remarkWin.document.write(content);
	}
}

function doViewDoc(url, allowed) {

	if (!allowed) {
		alert("This document is not viewable nor editable.");
		return false;
	}

	if(!confirmExit("")){
		return false;
	}
	
	location.href=url;
}

function doRemoveCommas() {
  var inputs = document.getElementsByTagName('input');
  for (var i = 0; i < inputs.length; ++i) {
    if (inputs[i].className == 'number') {
      inputs[i].value = inputs[i].value.replace(/,/g, '');
    }
  }
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function doAddCommas(input) {
  if (input.length) {
    for (var i = 0; i < input.length; ++i) {
      input[i].value = addCommas(input[i].value);
    }
  } else {
    input.value = addCommas(input.value);
  }
}

function doAllAddCommas() {
  var inputs = document.getElementsByTagName('input');
  for (var i = 0; i < inputs.length; ++i) {
    if (inputs[i].className == 'number') {
      doAddCommas(inputs[i]);
    }
  }
}

function objectFocus(win,e,txt)
{
	var src=getTarget(e);
	if(src.value==txt)
	{src.value="";src.style.color ="";}
}

function objectBlur(win,e,txt,form)
{
	var src=getTarget(e);
	var ivJids=document.getElementById(form);
	if(src.value==""||src.value.replace(/\s+/g,"")=="")
	{
		src.value=txt;
		src.style.color ="#676767";
		ivJids.value= ""
	}
	else
	{ivJids.value=src.value}
}
function getTarget(e)
{     var target;
      if(!e){var e=window.event}

	  if(e.target)
	  {target=e.target}
	  else if(e.srcElement)
	  {target=e.srcElement}

	  if(target.nodeType==3){target=target.parentNode}

	  return target
}

String.prototype.lTrim = function() { return this.replace(/^\s+/g, ''); };
String.prototype.rTrim = function() { return this.replace(/\s+$/g, ''); };
String.prototype.allTrim = function() { return this.lTrim().rTrim(); };
